import Vue from 'vue'
import axios from 'axios'
// 配置请求的跟路径
axios.defaults.baseURL = 'http://192.168.82.74:8888/api/private/v1/'
// axios.defaults.baseURL = 'http://192.168.1.15:8888/api/private/v1/'
// axios.defaults.baseURL = 'http://klxin.cn:8888/api/private/v1/'
// axios.defaults.baseURL = 'http://localhost:8888/api/private/v1/'
// Vue.prototype.$http = axios

//请求拦截   
axios.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem('token')
  // 在最后必须 return config
  return config
})

//登录
export var login_api = (params) => {
  return axios.post('login', params)
}

//获取home页面左侧列表的数据
export var homeList = () => {
  return axios.get('menus')
}
//获取home页面中用户数据列表
export var usersList = (params) => {
  return axios.get('users', {
    params
  })
}

//修改用户状态
export var getCondition = (params) => {
  return axios.put(`users/${params.id}/state/${params.type}`);
}
//添加用户功能
export var getAddUserForm = (params) => {
  return axios.post('users', params);
}
//修改用户功能
export var getEditUserForm = (id, params) => {
  return axios.put(`users/${id}`, params);
}
//用户分配角色额功能
export var getRolesUserForm = (id, rid) => {
  // console.log(id,rid);
  return axios.put(`users/${id}/role`, {
    rid: rid
  });
}
//删除用户功能
export var getDelUserForm = (id) => {
  return axios.delete(`users/${id}`);
}



//权限管理  获取角色列表
export var authorityUser = () => {
  return axios.get('roles');
}

//获取权限列表
export var getRightsList = (type) => {
  return axios.get(`rights/${type}`);
}
//删除用户列表
export var deleteRights = (id) => {
  return axios.delete(`roles/${id}`);
}

//删除指定权限
export var deleRolesId = (params) => {
  return axios.delete(`roles/${params.roleId}/rights/${params.rightId}`);
}

//根据角色授权
export var getImpowerRole = (roleId, params) => {
  return axios.post(`roles/${roleId}/rights`, {
    rids: params
  });
}


//获取商品分类
export var categoriesList = (params) => {
  return axios.get('categories', {
    params
  });
}
//添加商品分类
export var addCategoriesList = (params) => {
  return axios.post('categories', params);
}
//删除商品分类
export var deleteCategories = (id) => {
  return axios.delete(`categories/${id}`);
}
//删除商品
export var deleteGoods = (id) => {
  return axios.delete(`goods/${id}`);
}


//获取分类参数列表
export var paramsList = (params) => {
  return axios.get(`categories/${params.id}/attributes`, {
    params: {
      sel: params.sel
    }
  });
}
//添加动态参数或者静态属性
export var addCategories = (id, params) => {
  return axios.post(`categories/${id}/attributes`, params);
}
//删除参数
export var deleteParams = (params) => {
  return axios.delete(`categories/${params.id}/attributes/${params.attrid}`);
}
//编辑提交参数
export var editParams = (params) => {
  return axios.put(`categories/${params.id}/attributes/${params.attrid}`, {
    attr_name: params.attr_name,
    attr_sel: params.attr_sel,
    attr_vals: params.attr_vals
  });
}

//商品列表参数
export var goodsList_api = (params) => {
  return axios.get('goods',{params})
}
//添加商品参数
export var addGoodsList_api = (params) => {
  return axios.post('goods',params)
}
//获取订单列表
export var OrdersList_api = (params) => {
  return axios.get('orders',{params})
}
//获取订单列表
export var addrOrdersList_api = (id) => {
  return axios.get(`/kuaidi/${id}`)
}
//获取订单列表
export var reports_api = () => {
  return axios.get('reports/type/1')
}

